package org.example.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.example.Inventory;
import org.example.Order;
import org.example.ResultMap;
import org.example.mapper.InventoryMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.object.UpdatableSqlQuery;
import org.springframework.stereotype.Service;

@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    InventoryMapper inventoryMapper;

    @Override
    public ResultMap updateInventory(Order orders) {
        ResultMap resultMap = new ResultMap();
        int pid = orders.getPid();
        int oCount = orders.getOcount();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("pid", pid);
        Inventory inventory = inventoryMapper.selectOne(queryWrapper);
        inventory.setIcount(inventory.getIcount() - oCount);
        int update = inventoryMapper.updateById(inventory);
        resultMap.setMsg("更新");
        resultMap.setCode(1);
        return resultMap;
    }
}
